import { Controller, Post, Body, HttpCode, HttpStatus } from '@nestjs/common';
import { AuthService } from './auth.service';
import { RegisterDto } from './dto/register.dto';
import { LoginDto } from './dto/login.dto';
import { SendCaptchaDto } from './dto/send-captcha.dto';

@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  @Post('register')
  async register(@Body() registerDto: RegisterDto) {
    const data = await this.authService.register(registerDto);
    return {
      code: 200,
      message: '注册成功',
      data,
      timestamp: Date.now(),
    };
  }

  @Post('login')
  @HttpCode(HttpStatus.OK)
  async login(@Body() loginDto: LoginDto) {
    const data = await this.authService.login(loginDto);
    return {
      code: 200,
      message: '登录成功',
      data,
      timestamp: Date.now(),
    };
  }

  @Post('send-captcha')
  @HttpCode(HttpStatus.OK)
  async sendCaptcha(@Body() sendCaptchaDto: SendCaptchaDto) {
    const data = await this.authService.sendCaptcha(sendCaptchaDto);
    return {
      code: 200,
      message: '验证码发送成功',
      data,
      timestamp: Date.now(),
    };
  }
}
